/*
 * @Description:这个函数是一个简单的封装，使得在组件的 `setup` 脚本中获取 WebSocket 实例变得非常容易和类型安全。
 * @Author: redxing96@163.com
 * @Date: 2025-09-22 13:49:47
 * @LastEditTime: 2025-09-22 13:49:58
 * @LastEditors: front end cabbage
 * @FilePath: /dora-admin/src/composables/useWebSocket.ts
 */
import { inject } from "vue";
import { WebSocketInjectKey } from "@/plugins/websocket";
import type { WebSocketService } from "@/services/websocketService";

export function useWebSocket(): WebSocketService {
  // 通过 inject 和 InjectionKey 获取插件提供的全局实例
  const wsService = inject(WebSocketInjectKey);

  if (!wsService) {
    throw new Error("Could not inject WebSocket service. Did you forget to install the plugin with app.use()?");
  }

  return wsService;
}
